<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>充值返现</title>
    <script type="text/javascript">
        document.addEventListener('plusready', function(){
            //console.log("所有plus api都应该在此事件发生后调用，否则会出现plus is undefined。"
        });
    </script>
    <link rel="stylesheet" href="{php echo $this->cur_mobile_path}/css/style.css" />
    <link rel="stylesheet" href="{php echo $this->cur_mobile_path}/mvalidate/validate.css" />
    <script src="{php echo $this->cur_mobile_path}/script/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="{RES}/js/fastclick.js" ></script>
    <script type="text/javascript" src="{php echo $this->cur_mobile_path}/mvalidate/jquery-mvalidate.js" ></script>
    <script>
        $(function() {
            FastClick.attach(document.body);
        });
    </script>
    <style>
        select{
            padding-left: 0;
            height: 32px;
            line-height: 32px;
            font-size: 14px;
            width: 100%;
            border: 0px;
        }
    </style>
</head>
<body class="grey">
<div class="pay_name">
    <img src="{php echo $this->cur_mobile_path}/image/shouyin.png">
    <span>充值返现</span>
</div>
<div class="box">
    <div class="pay_money">
        <p>金额（元）</p>
        <div class="inp_money">
                <select id="input_price">
                    {loop $list $item}
                    <option value="{$item['recharge_value']}">
                        {$item['title']}
                    </option>
                    {/loop}
                </select>
        </div>
    </div>
</div>
<div class="money">
    <h3 class="clear">
        <label class="fl">实际支付</label>
        <b class="fr shiji"></b>
        <input type="hidden" name="totalprice" id="totalprice">
    </h3>
</div>
<div class="inp_word">
    <input type="text" placeholder="捎句话..." id="remark">
</div>
<div class="pay_to">
    <a href="javascript:go_pay();void(0);">微信支付</a>
    <p>支付完成后，如需退款请及时联系卖家</p>
</div>
<div class="lo">
    <!--<img src="{php echo $this->cur_mobile_path}/img/logo.png">-->
    {if !empty($config['copyright_name'])}
    <p>{$config['copyright_name']}</p>
    {else}
    <p>码上点餐技术支持</p>
    {/if}
</div>
<script>
    $('#input_price').change(function(){
        var input_price = $('#input_price').val();
        $('.youhui').html('');

        if(parseFloat(input_price).toFixed(2)<0.01 || parseFloat(input_price).toFixed(2)=='NaN'){
            $('.shiji').html('请重新输入金额');
            $('#input_price').val('');
        }else{
            $('.shiji').html('¥'+(parseFloat(input_price)).toFixed(2));
        }
        $('#totalprice').val((parseFloat(input_price)).toFixed(2));
    });
</script>
<script>
    function go_pay(){
        {if $store['wechat'] == 0}
//            $.mvalidateTip("商家未开通微信支付，不支持收银功能！");
//            return false;
        {/if}

        var input_price = $('#input_price').val();
        if(!input_price){
            $.mvalidateTip("请输入支付金额");
            return false;
        }
        if(parseFloat(input_price).toFixed(2)<0.01 || parseFloat(input_price).toFixed(2)=='NaN'){
            $.mvalidateTip("请重新输入金额");
            $('#input_price').val('');
            return false;
        }

        var url = "{php echo $this->createMobileUrl('addtoorder', array('storeid' => $storeid, 'from_user' => $from_user), true)}";
        var totalprice = parseFloat($('#totalprice').val());
        var remark = $('#remark').val();

        $.ajax({
            url: url, type: "post", dataType: "json", timeout: "10000",
            data: {
                "type": "add",
                "total": totalprice,
                "remark": remark,
                "ordertype":6
            },
            success: function (data) {
                if (data.message['code'] != 0) {
                    var url = "{php echo $this->createMobileUrl('pay', array(), true)}" + "&orderid=" + data.message['orderid'];
                    location.href = url;
//                    $('#params').val(data.message['params']);
//                    $('#payform').submit();
                } else {
                    alert(data.message['msg']);
                }
            },error: function () {
                alert("订单提交失败！");
            }
        });
    }
    function ch_none(a){
        $(a).css({"background":"none"})
    }

    $(document).ready(function(){
        var input_price = $('#input_price').val();
        $('#totalprice').val((parseFloat(input_price)).toFixed(2));
        $('.shiji').html('¥'+(parseFloat(input_price)).toFixed(2));
    });
</script>
<form action="{php echo url('mc/cash/wechat');}" method="post" id="payform">
    <input type="hidden" name="params" id="params" value="" />
    <input type="hidden" name="code" value="" />
    <input type="hidden" name="coupon_id" value="" />
</form>
</body>
</html>